import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.wsdl.WSDLException;
import javax.xml.stream.XMLStreamException;

import at.ac.tuwien.infosys.dsg.daios.exceptions.AmbigiousException;
import at.ac.tuwien.infosys.dsg.daios.exceptions.InvocationException;
import at.ac.tuwien.infosys.dsg.daios.framework.DefaultInterceptor;
import at.ac.tuwien.infosys.dsg.daios.framework.ServiceFrontend;
import at.ac.tuwien.infosys.dsg.daios.framework.ServiceFrontendFactory;
import at.ac.tuwien.infosys.dsg.daios.framework.interfaces.IConstants;
import at.ac.tuwien.infosys.dsg.daios.framework.interfaces.IServiceFrontendImplementor;
import at.ac.tuwien.infosys.dsg.daios.framework.structs.DaiosInputMessage;


public class HTTPLoggingExample {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws XMLStreamException 
	 * @throws AmbigiousException 
	 * @throws WSDLException 
	 * @throws MalformedURLException 
	 * @throws InvocationException 
	 */
	public static void main(String[] args) throws MalformedURLException, WSDLException,
		AmbigiousException, XMLStreamException, IOException, InvocationException {
		
		Logger.getLogger(IConstants.LOG_NAME).setLevel(Level.OFF);
		
//		 create factory as usual
		ServiceFrontendFactory factory = ServiceFrontendFactory.getFactory
			("at.ac.tuwien.infosys.dsg.daiosPlugins.nativeInvoker.NativeServiceInvokerFactory");

//		 create frontend with an (anonymous) HTTP logger
		ServiceFrontend frontend = factory.createFrontend(
		  new URL("http://localhost:8080/axis2/services/DADocTestService?wsdl"),
		  "SOAP",
		  new DefaultInterceptor() {

		    public void doHTTPInvocation(String endpoint, String body,
		      IServiceFrontendImplementor invoker) {
								
		      System.out.println("HTTP Request: ");
		      System.out.println(body);
								
		    }

		    public void receiveHTTPResult(String endpoint, String body,
		      IServiceFrontendImplementor invoker, String response) {
								
		      System.out.println("HTTP Response: ");
		      System.out.println(response);
								
		    }
							
		  });
		
		DaiosInputMessage in = new DaiosInputMessage();
		in.setStringArray("param1",
			new String[] {
				"Philipp Leitner",
				"Florian Rosenberg"
		    }
		);
		in.setInt("param0", 2);
		
		frontend.requestResponse(in);
		
	}

}
